import 'package:boss/provider/commodity_provider.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusPackage/provider/package_detail_provider.dart';
import 'package:boss/ui/widget/button/fixed_bottom_btn.dart';
import 'package:boss/ui/widget/column_divier.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'base_panel.dart';
import 'description_panel.dart';
import 'package_commodity_panel.dart';
import 'package_image.dart';
import 'sell_panel.dart';

class PlusPackageBrowser extends StatefulWidget {
  @override
  _PlusPackageBrowserState createState() => _PlusPackageBrowserState();
}

class _PlusPackageBrowserState extends State<PlusPackageBrowser> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: SingleChildScrollView(
            padding: EdgeInsets.zero,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Consumer<PackageDetailProvider>(
                  builder: (context, provider, child) {
                    return PackageImage(
                      imageUrl: provider.package.images,
                      onUploaded: (url) {
                        provider.setPackageImage(url);
                      },
                    );
                  },
                ),
                ColumnDivier(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    BasePanel(),
                    PackageCommodityPanel(),
                    DescriptionPanel(),
                    SellPanel(),
                  ],
                ),
              ],
            ),
          ),
        ),
        FixedBottomBtn(
          title: '保 存',
          onTap: () async {
            var commodityProvider = Provider.of<CommodityProvider>(
              context,
              listen: false,
            );
            var packageDetailProvider = Provider.of<PackageDetailProvider>(
              context,
              listen: false,
            );

            if (await commodityProvider.plusPackage(packageDetailProvider.package)) {
              Navigator.pop(context);
            }
          },
        ),
      ],
    );
  }
}
